package com.itcast.mallapplet.mapper;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itcast.applet.entity.Shopping;
import com.itcast.applet.entity.ShoppingDh;
import com.itcast.applet.entity.ShoppingPrice;
import com.itcast.applet.vo.ShoppingDhVO;
import com.itcast.applet.vo.ShoppingDityAll;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ShoppingMapper {
    //根据用户注册自动创建用户购物车
    @Insert("insert into shopping(user_id,price,number) values (#{userId},#{price},#{number})")
    void insertShop(Shopping shopping);

    //构建购物车分表
    @Insert("insert into shopping_dh(name, number, price, dity_id, shopping_id) values (#{name}, #{number},#{price},#{dityId},#{shoppingId})")
    void insertshoppingDh(ShoppingDh shoppingDh);

    //判断购物车分表里面是否有这个商品id
    @Select("select * from shopping_dh where dity_id = #{id}")
    ShoppingDh getByDity(Long id);

    //根据主键判断购物车分表里面是否有这个商品id
    @Select("select * from shopping_dh where id = #{id}")
    ShoppingDh getById(Long id);

    //修改分表数据
    void amendShoppingDh(ShoppingDh shopDh1);

    //根据shopingID查分表全部数量
    @Select("select * from shopping_dh where shopping_id = #{id}")
    List<ShoppingDh> getByShoppingDhId(Long id);

    //根据userId找到主购物车
    @Select("select * from shopping where user_id = #{userId}")
    Shopping getByShoppingId(Long userId);

    //修改购物车主表
    void amendShopping(Shopping shopping);

    //删除购物车商品
    void deleteShopping(List<Long> ids);

    //通过id批量找商品数据
    List<ShoppingPrice> seletShopping(List<Long> ids);

    //分页查询购物车用户的商品数据
    Page<ShoppingDhVO> pageQueryShoppingAll(Long userId , Integer page, Integer pageSize);
}
